package com.zzh.myapplication.activity;

import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import net.icarplus.car.R;
import net.icarplus.car.fragment.coupon.EndDeadLineFragment;
import net.icarplus.car.fragment.coupon.EndUseFragment;
import net.icarplus.car.fragment.coupon.NotUseCouponFragment;
import net.icarplus.car.manager.BaseActivity;
import net.icarplus.car.tools.ToolBarHelper;

/**
 * Created by Administrator on 2016/3/18.
 */
public class CouponActiviity extends BaseActivity {
    private Toolbar toolbar;
    public TextView tv_end_use;
    public TextView tv_end_deadline;
    public TextView tv_not_use;
    private FragmentTransaction transaction;
    private Fragment tabFragment;

    @Override
    public void setContent() {
        setContentView(R.layout.activity_coupon);
    }

    @Override
    public void initComponent() {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        ToolBarHelper.setNormalTitleAndBack(this, toolbar, getString(R.string.coupon));
        tv_end_use = (TextView) findViewById(R.id.tv_end_use);
        tv_not_use = (TextView) findViewById(R.id.tv_not_use);
        tv_end_deadline = (TextView) findViewById(R.id.tv_end_deadline);
    }

    @Override
    public void setListener() {
        tv_end_use.setOnClickListener(this);
        tv_not_use.setOnClickListener(this);
        tv_end_deadline.setOnClickListener(this);
    }

    private void switchFragment(Fragment fragment) {
        transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.fl_coupon, fragment);
        transaction.commit();
    }

    @Override
    public void onAfterInit() {
        tabFragment = new  NotUseCouponFragment();
        switchFragment(tabFragment);
        tv_not_use.setTextColor(Color.parseColor("#ffb226"));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_not_use:
                tabFragment = new  NotUseCouponFragment();
                switchFragment(tabFragment);
                tv_not_use.setTextColor(Color.parseColor("#ffb226"));
                tv_end_use.setTextColor(Color.BLACK);
                tv_end_deadline.setTextColor(Color.BLACK);
                break;
            case R.id.tv_end_use:
                tabFragment = new EndUseFragment();
                switchFragment(tabFragment);
                tv_not_use.setTextColor(Color.BLACK);
                tv_end_use.setTextColor(Color.parseColor("#ffb226"));
                tv_end_deadline.setTextColor(Color.BLACK);
                break;
            case R.id.tv_end_deadline:
                tabFragment = new EndDeadLineFragment();
                switchFragment(tabFragment);
                tv_end_deadline.setTextColor(Color.parseColor("#ffb226"));
                tv_end_use.setTextColor(Color.BLACK);
                tv_not_use.setTextColor(Color.BLACK);
                break;

        }
    }
}
